import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';
export default {
  //获取全局设置数据
  getGlobalSetting(params){
    return httpFetch.get(`${config.pushUrl}/api/customizedApiCallback/companyCallback`,params)
  },

  //修改全局设置
  updateGlobalSetting(params){
    return httpFetch.post(`${config.pushUrl}/api/customizedApiCallback/company`,params)
  },

  //获取api列表
  getApiColumn(params){
    return httpFetch.get(`${config.pushUrl}/api/customizedApi`,params)
  },

  //获取api设置
  getApiSetting(params){
    return httpFetch.get(`${config.pushUrl}/api/customizedApiCallback`,params)
  },

  //获取是否启用全局设置
  getIsEnabled(params){
    return httpFetch.get(`${config.baseUrl}/api/customizedApiCallback/config`,params)
  },

  //改变全局设置状态
  updateGlobalStatus(params){
    return httpFetch.post(`${config.baseUrl}/api/customizedApiCallback/config`,params)
  },

  //获取apiCode
  getApiCode(params){
    return httpFetch.get(`${config.pushUrl}/api/customizedApi`,params)
  },

  //回调地址验证
  validateCallback(params){
    return new Promise((resolve, reject) => {
      httpFetch.post(`${config.pushUrl}/api/customizedApiCallback/validateCallbackUrl` ,params)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
  //新建api回调设置
  addCallbackSetting(params){
    return new Promise((resolve, reject) => {
      httpFetch.post(config.pushUrl + '/api/customizedApiCallback' ,params)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },

  //更新api回调设置
  updateCallbackSetting(params){
    return new Promise((resolve, reject) => {
      httpFetch.put(config.pushUrl + '/api/customizedApiCallback' ,params)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err);
        })
    })
  }
}
